package Io;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

public class SteatMain
{
	public static void main(String[] args)
	{
		System.out.println("=======");
//		readFile();
		readChese();
	}

	private static void readChese()
	{
		FileInputStream file_2 =null;
		try
		{	
			byte d [] = new byte[3];
			BufferedInputStream bis = new BufferedInputStream(file_2);
			file_2 = new FileInputStream("D:/a/b.txt");
			int res = 0;
//			int len = 0;
			while ((res=file_2.read(d))!=-1)
			{
				String re = new String(d,0,res);
				System.out.println("res"+Arrays.toString(d)+re);
			}
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}catch (IOException e)
		{
			e.printStackTrace();
		}finally
		{
			try
			{
				if(file_2 != null)
				{
					/* 水管套水管,关的时候,关最近的 */
					file_2.close();
					file_2 = null ;
				}
			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}

		
	}

	private static void readFile()
	{
		FileInputStream file_1 = null;
		try
		{
			file_1 = new FileInputStream("D:/a/a.txt");
//			int res = file_1.read();
//			System.out.println("res->"+res+"-->"+((char)res));
			byte [] b = new byte[3]; 
			int res = 0;
			while ((res = file_1.read(b))!=-1)
			{
//				int res = file_1.read(b);
				System.out.println(res+"-->"+Arrays.toString(b));
/*				if( (file_1.read()) == -1)
				{
					break;
				}*/
			}
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}finally {
			try
			{
				file_1.close();
			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}
	}
}
